package com.yqkj.zysoft.upms.controller;


import  com.project.easy.common.util.constants.SysModelConstant;
import  com.project.easy.common.util.constants.VersionConstant;
import  com.project.easy.common.util.dto.CommonContextParam;
import  com.project.easy.common.util.dto.OneLongApiContextParam;
import  com.project.easy.common.util.dto.R;
import com.project.easy.common.framework.web.annotation.ApiValidator;
import com.project.easy.common.log.annotation.Logging;
import com.project.easy.common.framework.web.controller.BaseController;

import com.yqkj.zysoft.upms.entity.dto.FrameWorkFunctionAddRequest;
import com.yqkj.zysoft.upms.entity.dto.FrameWorkFunctionUpdateRequest;
import com.yqkj.zysoft.upms.entity.dto.FunctionTreeDto;
import com.yqkj.zysoft.upms.entity.dto.QueryFunctionRequest;
import com.yqkj.zysoft.upms.service.IFrameworkFunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 功能前端控制器
 * </p>
 *
 * @author GreatorMan.cool
 * @since 2022-08-10
 */
@RestController
@RequestMapping("/api/" + VersionConstant.ONE + "/upms/function")
public class FrameworkFunctionController extends BaseController {

    @Autowired
    private IFrameworkFunctionService frameworkFunctionService;

    /**
     * 新增
     * @param frameWorkFunctionAddRequest 参数
     * @return 返回数据
     */
    @PostMapping("/add")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Long> add(@RequestBody FrameWorkFunctionAddRequest frameWorkFunctionAddRequest) {
        return R.success(frameworkFunctionService.add(frameWorkFunctionAddRequest));
    }
    /**
     * 修改
     * @param frameWorkFunctionUpdateRequest 参数
     * @return 返回数据
     */
    @PostMapping("/udpate")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> udpate(@RequestBody FrameWorkFunctionUpdateRequest frameWorkFunctionUpdateRequest) {
        return R.success(frameworkFunctionService.updateObject(frameWorkFunctionUpdateRequest));
    }
    /**
     * 树列表管理
     * @param queryFunctionRequest 参数
     * @return 返回数据
     */
    @PostMapping("/tree")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<List<FunctionTreeDto>> tree(@RequestBody QueryFunctionRequest queryFunctionRequest) {
        return R.success(frameworkFunctionService.tree(queryFunctionRequest));
    }

    /**
     * 删除
     * @param sysParamDto 参数
     * @return 返回数据
     */
    @PostMapping("/del")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> del(@RequestBody OneLongApiContextParam sysParamDto) {
        return R.success(this.frameworkFunctionService.del(sysParamDto.getKey()));
    }
    /**
     * 禁用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/disAble")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> disAble(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkFunctionService.disAble(oneApiContextParam.getKey()));
    }
    /**
     * 启用
     * @param oneApiContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/able")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator
    public R<Boolean> able(@RequestBody OneLongApiContextParam oneApiContextParam) {
        return R.success(this.frameworkFunctionService.able(oneApiContextParam.getKey()));
    }

    /**
     * 登陆后菜单
     * @param commonContextParam 参数
     * @return 返回数据
     */
    @PostMapping("/menu")
    @Logging(value = SysModelConstant.UPMS)
    @ApiValidator(hasAuth = false)
    public R<List<FunctionTreeDto>> menu(@RequestBody @Validated CommonContextParam commonContextParam) {
        return  R.success(this.frameworkFunctionService.menu(commonContextParam));
    }
}
